import cv2
import numpy as np
box_width = 192
global_mask = cv2.imread("model/alpha.jpg")
h, w = global_mask.shape[:2]
global_mask = global_mask[2:h-2, 24:w-24]
global_mask = cv2.resize(global_mask, (box_width, box_width),interpolation=cv2.INTER_AREA)
global_mask = cv2.cvtColor(global_mask, cv2.COLOR_BGR2GRAY).astype(np.float32)
 # 获取最大值
max_value = np.max(global_mask)
#print(f"全局掩码的最大值: {max_value}")

# 创建等于最大值的掩码（布尔数组）
max_pixels_mask = (global_mask >= max_value)

# 统计最大值像素的数量
max_pixels_count = np.count_nonzero(max_pixels_mask)
#print(f"等于最大值的像素数量: {max_pixels_count}")

# 将掩码转换为可视化形式（0和1）
visualization = max_pixels_mask.astype(np.float32)

cv2.imshow("visualization", visualization * 255.0)
#/ 255.0

global_mask = global_mask / 255.0
print("#ifndef __FACEMASK_H__")
print("#define __FACEMASK_H__")
print(f"//in [box_width]")
print("float face_mask[] = {")
for i in global_mask:
    for j in i:
        print(j,end=",")
    print("")
print("};")
print("#endif")

cv2.imshow("global", global_mask)
# print(global_mask)
cv2.waitKey()
